#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

#include "packbits.hpp"
#include "../tests/doctest.hpp"

using namespace std;

bool compareArrays(const uint8_t *a, const uint8_t *b, size_t size);

TEST_CASE("testing pack())") {
    const vector<uint8_t> unpackedBytes = {
        0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0xAA, 0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
    };
    vector<uint8_t> packedBytes = packbits::pack(unpackedBytes);
    vector<uint8_t> packed = { 0xFE, 0xAA, 0x02, 0x80, 0x00, 0x2A, 0xFD, 0xAA, 0x03, 0x80, 0x00, 0x2A, 0x22, 0xF7, 0xAA };
    bool areEqual = compareArrays(packedBytes.data(), packed.data(), packedBytes.size());
    CHECK(areEqual);
}

TEST_CASE("testing unpack())") {
    vector<uint8_t> packedBytes = { 0xFE, 0xAA, 0x02, 0x80, 0x00, 0x2A, 0xFD, 0xAA, 0x03, 0x80, 0x00, 0x2A, 0x22, 0xF7, 0xAA };
    vector<uint8_t> unpackedBytes = packbits::unpack(packedBytes);
    const vector<uint8_t> unpacked = {
        0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0xAA, 0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
    };
    bool areEqual = compareArrays(unpackedBytes.data(), unpacked.data(), unpackedBytes.size());
    CHECK(areEqual);
}

bool compareArrays(const uint8_t *a, const uint8_t *b, size_t size) {
    for (size_t i = 0; i < size; ++i) {
        if (a[i] != b[i]) {
            return false;
        }
    }
    return true;
}